package com.checkCode.strategy;

import com.checkCode.entity.dto.CheckCodeResultDto;
import com.checkCode.entity.vo.CheckCodeParamsVo;
import com.checkCode.service.serviceImpl.CheckCodeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 大忽悠
 * @create 2023/2/9 21:09
 */
@Component
public class CodeGeneratorStrategyHolder {
    @Autowired
    private List<CodeGeneratorStrategy> codeGeneratorStrategies;

    public CheckCodeResultDto generate(CheckCodeParamsVo checkCodeParamsVo, CheckCodeServiceImpl.CodeInfo code) {
        for (CodeGeneratorStrategy codeGeneratorStrategy : codeGeneratorStrategies) {
                  if(codeGeneratorStrategy.support(checkCodeParamsVo)){
                      return codeGeneratorStrategy.generate(checkCodeParamsVo,code);
                  }
        }
        throw new UnsupportedOperationException("不支持当前类型验证码生成");
    }
}
